//高阶组件----
import React from "react"

export default function TestHoc(Uercom){
    return class extends React.Component{
        //模拟鼠标移动实时位置
        // componentDidMount(){
        //     window.addEventListener('mousemove',(e)=>{
        //         let x = e.clientX
        //         let y = e.clientY
        //         this.setState({
        //             ...this.state,
        //             x,
        //             y
        //         })
        //     })
        // }


        //模拟pureComponent  如果只有父组件的数据发生改变---来判断子组件是不是需要更新   
        shouldComponentUpdate(props,state){
            let needupdate = false
            for(let item in props){
                if(props[item] !== this.props[item]){
                    needupdate = true
                    break
                }
            }

            for(let item in props){
                if(state[item] !== this.state[item]){
                    needupdate = true
                    break
                }
            }

            return needupdate
        }
        state = {
            a:"我是高阶组件里面的数据",
            x:0,
            y:0
        }
        render(){
            console.log("子组件被更新了")
            return <Uercom a={this.state.a} x={this.state.x} y={this.state.y} {...this.props}/>
        }
    }
}

